/**
 * @package: BrickCAD
 * @className: SideView.java
 * @package: default
 * @author: Sean O'Brien, Jack, Lester Tam, Erik Telstad
 * @date_created: November 16, 2009
 * @last_motified: November 16, 2009
 * 
 * 
 * 
 */


import java.util.Observable;



public class SideView extends BrickView {

	private static final long serialVersionUID = 1L;
	private static String title = "Side View";
	static int openFrameCount = 0;
	static final int xOffset = 60, yOffset = 5;
	
	private BrickImagePanel sideImage;

	/**
	 * @param theModel
	 */
	public SideView(Brick theModel) {
		super(theModel);
		setTitle(title);
		openFrameCount++;
		setSize(300, 300);
		this.setLocation(xOffset*openFrameCount, yOffset*openFrameCount);

		double x =(this.getX() + (this.getWidth()/2.0)) - model.getWidth()/2.0;
		double y =(this.getY() + (this.getHeight()/2.0)) - model.getHeight()/2.0;
		sideImage = new BrickImagePanel(x, y, model.getWidth(), model.getHeight());
		//contentPane = new JPanel(new BorderLayout());
		//getContentPane().add(sideImage, BorderLayout.CENTER);
		add(sideImage);
		pack();
	}
	
	/* (non-Javadoc)
	 * @see BrickView#update(java.util.Observable, java.lang.Object)
	 */
	@Override
	public void update(Observable arg0, Object o) {
		System.out.println("Updating SideView #" + openFrameCount);
		model = (Brick) arg0;
		if(sideImage.getWidth() != model.getWidth()) {
			System.out.print("Brick width: " + model.getWidth());
			sideImage.setBrickWidth(model.getWidth());
		}
		if(sideImage.getHeight() != model.getHeight()) {
			System.out.print(" Brick height: " + model.getHeight());
			sideImage.setBrickHeight(model.getHeight());
		}
		System.out.println();
		sideImage.repaint();
	}
}
